<?php

namespace app\admin\validate;

use think\Validate;

class Isgoods extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */
	protected $rule = [
        "name"       => "require",
        "files_url"  => "require",
        "num_buy"    => "checkNum",
        "cost"       => "checkCost",
        "num_limit"  => "checkNum"
    ];


    //验证购买数量
    public function checkNum($val){
        return $val<0?false:true;
    }


    //兑换金额
    public function checkCost($cost){
        return (!is_numeric($cost)||$cost<=0)?false:true;
    }

    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */
    protected $message = [
        "name.require"         => '请输入商品名称',
        "files_url.require"    => '请上传图片',
        "num_buy.checkNum"     => '兑换数量不能为负数',
        "cost.checkCost"        => '兑换积分不正确',
        "num_limit.checkNum"   => '限购数量不能为负数'
    ];

}
